import { http } from "@/utils/http";
import { adminUrlApi } from "@/utils/http/utils";
import type { Result, ResultTable } from "@/utils/http/utils";

/** 获取系统管理-用户管理列表 */
export const getUserList = (data?: object) => {
  return http.request<ResultTable>(
    "get",
    adminUrlApi("user/getPageList"),
    { data }
  );
};

/** 上传图片 */
export const uploadImage = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("admin/Upload/image"), {
    data
  });
};

/** 上传base64图片 */
export const uploadBase64Image = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("file/uploadBase64"), {
    data
  });
};

/** 系统管理-用户添加 */
export const addUser = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("user/create"), {
    data
  });
};

/** 系统管理-用户修改 */
export const editUser = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("user/update"), {
    data
  });
};

/** 系统管理-用户删除 */
export const delUser = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("user/delete"), {
    data
  });
};

export const exportUser = (data?: object) => {
  return http.request<any>(
    "post",
    adminUrlApi("admin/systemUser/export"),
    {
      data
    },
    {
      responseType: "blob"
    }
  );
};

/** 系统管理-用户信息修改*/
export const userResetInfo = (data?: object) => {
  return http.request<Result>(
    "post",
    adminUrlApi("user/reset"),
    {
      data
    }
  );
};

/** 系统管理-用户管理-获取所有角色列表 */
export const getAllRoleList = () => {
  return http.request<Result>("get", "/list-all-role");
};

/** 系统管理-用户管理-根据userId，获取对应角色id列表（userId：用户id） */
export const getRoleIds = (data?: object) => {
  return http.request<Result>("post", "/list-role-ids", { data });
};

/** 获取系统管理-角色管理列表 */
export const getRoleList = (data?: object) => {
  return http.request<ResultTable>(
    "get",
    adminUrlApi("role/getPageList"),
    {
      data
    }
  );
};

/** 系统管理-角色添加 */
export const addRole = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("role/create"), {
    data
  });
};

/** 系统管理-角色修改 */
export const editRole = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("role/update"), {
    data
  });
};

/** 系统管理-角色删除 */
export const delRole = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("role/delete"), {
    data
  });
};

/** 系统管理-角色修改状态 */
export const editStatusRole = (data?: object) => {
  return http.request<Result>(
    "post",
    adminUrlApi("admin/systemRole/editStatus"),
    {
      data
    }
  );
};

/** 获取系统管理-菜单管理列表 */
export const getMenuList = (data?: object) => {
  return http.request<ResultTable>(
    "get",
    adminUrlApi("menu/getList"),
    {
      data
    }
  );
};

/** 获取系统管理-菜单添加 */
export const addMenu = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("menu/create"), {
    data
  });
};

/** 获取系统管理-菜单修改 */
export const editMenu = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("menu/update"), {
    data
  });
};

/** 系统管理-菜单删除 */
export const delMenu = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("menu/delete"), {
    data
  });
};

/** 获取系统管理-部门管理列表 */
export const getDeptList = (data?: object) => {
  return http.request<ResultTable>(
    "get",
    adminUrlApi("dept/getList"),
    { data }
  );
};

/** 获取系统管理-部门添加 */
export const addDept = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("dept/create"), {
    data
  });
};

/** 获取系统管理-部门修改 */
export const editDept = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("dept/update"), {
    data
  });
};

/** 系统管理-部门删除 */
export const delDept = (data?: object) => {
  return http.request<Result>("post", adminUrlApi("dept/delete"), {
    data
  });
};

/** 获取系统监控-在线用户列表 */
export const getOnlineLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/online-logs", { data });
};

/** 获取系统监控-登录日志列表 */
export const getLoginLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/login-logs", { data });
};

/** 获取系统监控-操作日志列表 */
export const getOperationLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/operation-logs", { data });
};

/** 获取系统监控-系统日志列表 */
export const getSystemLogsList = (data?: object) => {
  return http.request<ResultTable>("post", "/system-logs", { data });
};

/** 获取系统监控-系统日志-根据 id 查日志详情 */
export const getSystemLogsDetail = (data?: object) => {
  return http.request<Result>("post", "/system-logs-detail", { data });
};

/** 获取角色管理-权限-菜单权限 */
export const getRoleMenu = (data?: object) => {
  return http.request<Result>("get", adminUrlApi("menu/getRoleMenu"), {
    data
  });
};

/** 获取角色管理-权限-菜单权限-根据角色 id 查对应菜单 */
export const getRoleMenuIds = (data?: object) => {
  return http.request<Result>(
    "get",
    adminUrlApi("role/getRoleMenuIds"),
    {
      data
    }
  );
};

/** 更新角色菜单**/
export const syncRoleMenus = (data?: object) => {
  return http.request<Result>(
    "post",
    adminUrlApi("role/syncRoleMenus"),
    {
      data
    }
  );
};
